package com.jumper.mydemo.statics;

import java.io.IOException;

import org.springframework.context.annotation.Condition;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;

import com.jumper.mydemo.my.MyOnClassCondition;

public class ConditionDemo {
    public static void run() throws IOException {
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
		SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();

		Resource[] resources = resolver.getResources("classpath*:com/jumper/mydemo/**/*.class");
		Condition condition = new MyOnClassCondition("com.jumper.mydemo.MydemoApplication");

		for(Resource resource : resources) {
			MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);

			if (condition.matches(null, metadataReader.getAnnotationMetadata())) {
				System.out.println(resource.getFile().getName() + "满足条件");
			} else {
				System.out.println(resource.getFile().getName() + "不满足条件");
			}
		}
    }
}
